package com.nuotu.datawall.clouddata.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nuotu.datawall.clouddata.R;
import com.nuotu.datawall.clouddata.been.BasicData;
import com.nuotu.datawall.clouddata.been.ReaderCount;

import java.util.ArrayList;
import java.util.List;

public class ReaderCount_adapter extends BaseAdapter {

    private Context mContext;
    private List<ReaderCount> mGridData;
    public ReaderCount_adapter(Context context, List<ReaderCount> objects) {
        super();
        this.mContext = context;
        this.mGridData = objects;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        System.out.println(position);
        if (convertView == null) {
            LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
            convertView = inflater.inflate(R.layout.reader_count_item, parent, false);
            holder = new ViewHolder();
            holder.reader_count_xh = (TextView) convertView.findViewById(R.id.reader_count_xh);
            holder.reader_count_name = (TextView) convertView.findViewById(R.id.reader_count_name);
            holder.reader_count_department = (TextView) convertView.findViewById(R.id.reader_count_department);
            holder.reader_count_borrowCount = (TextView) convertView.findViewById(R.id.reader_count_borrowCount);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (mGridData.size()==0){
            holder.reader_count_xh.setText("");
            holder.reader_count_name.setText("");
            holder.reader_count_department.setText("");
            holder.reader_count_borrowCount.setText("");
            return convertView;
        }
        ReaderCount item = mGridData.get(position % mGridData.size());
        holder.reader_count_xh.setText(item.getXh()==-1?"一一一一":(item.getXh()+""));
        holder.reader_count_name.setText(item.getUserName());
        holder.reader_count_department.setText(item.getDepartmentName());
        holder.reader_count_borrowCount.setText(item.getNum()==-1?"一一一一一":(item.getNum()+""));
        return convertView;
    }
    private class ViewHolder {
        TextView reader_count_xh;
        TextView reader_count_name;
        TextView reader_count_department;
        TextView reader_count_borrowCount;
    }
    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public Object getItem(int i) {
        return mGridData.get(i % mGridData.size());
    }

    @Override
    public long getItemId(int i) {
        if(mGridData.size()==0){
            return 0;
        }
        return  i % mGridData.size();
    }


}
